package servlet;

import model.Order;
import model.User;
import model.Goods;
import service.GoodsService;
import service.OrderService;
import service.UserService;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "publish_goods_list", urlPatterns = "/publish_goods_list")
public class PublishGoodsListServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        GoodsService gService = new GoodsService();
        User user = (User) request.getSession().getAttribute("user");
        //登陆后直接获取对应用户发布的商品
//        List<Goods> list_isRemoved = gService.GetRemovedProducts(user.getId());
//        List<Goods> list_notRemoved = gService.GetNotRemovedProducts(user.getId());
//        List<Goods> allLists = new ArrayList<>();
//        if (list_isRemoved != null) allLists.addAll(list_isRemoved);
//        if (list_notRemoved != null) allLists.addAll(list_notRemoved);

        List<Goods> allLists = gService.GetProductsByUserId(user.getId());
        //将获取的list表格通过orderList字段传给前端
        request.getSession().setAttribute("publishGoodsList", allLists);
        request.getRequestDispatcher("/history_goods_publish.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }


}